let sqlUtil = require("../util/SqlUtil");
const mysql = require("mysql");
const mysqlConfig = require("./config/mysql.config");
const syncMysql = require("sync-mysql");


let sqlConnection = mysql.createConnection({
    host: mysqlConfig.host,
    user: mysqlConfig.user,
    password: mysqlConfig.password,
    database: mysqlConfig.database
});


let syncSqlConnection = new syncMysql({
    host: mysqlConfig.host,
    user: mysqlConfig.user,
    password: mysqlConfig.password,
    database: mysqlConfig.database
});

sqlConnection.connect();
sqlUtil.init(sqlConnection, syncSqlConnection);
// 全局挂在sqlConnection
global.sqlConnection = sqlConnection;
global.sqlUtil = sqlUtil;
global.syncSqlConnection = syncSqlConnection;

module.exports = {
    sqlConnection,
    sqlUtil,
    syncSqlConnection
};
